package org.cmind.soap.android.envelope;

import org.cmind.soap.android.ComplexSoapObject;
import org.cmind.soap.android.SoapObject;

public class Envelope extends ComplexSoapObject {
    //Tag names
    static final String ENVELOPE_NAME = "Envelope";
    static final String HEADER_NAME = "Header";
    static final String BODY_NAME = "Body";
    
    private ComplexSoapObject body;
    private ComplexSoapObject header;
    private SoapVersion soapVersion;
    private EnvelopeBuilder builder;

    public SoapVersion getSoapVersion() {
        return soapVersion;
    }

    public void setSoapVersion(SoapVersion soapVersion) {
        this.soapVersion = soapVersion;
    }

    Envelope(ComplexSoapObject body, String namespace, EnvelopeBuilder builder) {
        super(ENVELOPE_NAME, namespace);
        addSoapObject(body);
        this.body = body;
        this.builder = builder;
    }

    Envelope(String namespace, EnvelopeBuilder builder) {
        super(ENVELOPE_NAME, namespace);
        this.builder = builder;
    }

    void setBody(ComplexSoapObject body) {
        this.body = body;
        this.addSoapObject(body);
    }

    void setHeader(ComplexSoapObject header) {
        this.header = header;
        this.addSoapObject(header);
    }

    public void addToBody(SoapObject object) {
        body.addSoapObject(object);
    }

    public void addToHeader(SoapObject object) {
        // 
        if (header == null) {
            setHeader(builder.createHeader());
        }
        header.addSoapObject(object);

    }

}
